package com.lagou.edu.service.impl;

import com.lagou.edu.service.LoginService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service
public class LoginServiceImpl implements LoginService {
    @Override
    public void logout(HttpSession session) {
        session.removeAttribute("user");
    }


    @Override
    public void login(String username, String password, HttpSession session) {
        if (!"admin".equals(username)) {
            throw new RuntimeException("用户名错误");
        }
        if (!"admin".equals(password)) {
            throw new RuntimeException("密码错误");
        }
        session.setAttribute("user", username);
    }

    @Override
    public boolean isLogin(HttpSession session) {
        return session.getAttribute("user") != null;
    }
}
